package opl.ui;

import opl.services.NotificationService;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

public class HomeActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		checkAndStartNotificationService();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.opl_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.settings) {
			showPreference();
		}
		if(item.getItemId()==R.id.logs){
			showLogs();
		}
		return true;
	}

	private void showLogs() {
		// TODO Auto-generated method stub
		Intent iLogs=new Intent(Intent.ACTION_VIEW,Uri.parse("opl://ui.logs"));
		startActivity(iLogs);
	}

	private void showPreference() {
		Intent intTeams = new Intent(Intent.ACTION_VIEW,
				Uri.parse("opl://ui.preference"));
		startActivity(intTeams);
	}
	
	private void checkAndStartNotificationService() {
		if(!NotificationService.isServiceRunning(this)){
			Intent intService=new Intent(this, NotificationService.class);
			startService(intService);
		}
	}

	public void btnTeams_Click(View v) {
		Intent intTeams = new Intent(Intent.ACTION_VIEW,
				Uri.parse("opl://ui.teams"));
		startActivity(intTeams);
	}

	public void btnFixture_Click(View v) {
		Intent intFixture = new Intent(Intent.ACTION_VIEW,
				Uri.parse("opl://ui.fixture"));
		startActivity(intFixture);
	}

	public void btnNotifications_CLick(View v) {
		Intent intNotifications = new Intent(Intent.ACTION_VIEW,
				Uri.parse("opl://ui.notifications"));
		startActivity(intNotifications);
	}
	
	public void btnAbout_CLick(View v) {
		Intent intAbout = new Intent(Intent.ACTION_VIEW,
				Uri.parse("opl://ui.about"));
		startActivity(intAbout);
	}
}
